package net.lab1024.sa.admin.module.business.file.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import net.lab1024.sa.admin.module.business.file.dao.ApprovordaDao;
import net.lab1024.sa.admin.module.business.file.domain.entity.ApprovordaEntity;
import net.lab1024.sa.admin.module.business.file.domain.form.add.ApprovordaAddForm;
import net.lab1024.sa.admin.module.business.file.domain.form.query.ApprovordaQueryForm;
import net.lab1024.sa.admin.module.business.file.domain.form.update.ApprovordaUpdateForm;
import net.lab1024.sa.admin.module.business.file.domain.vo.ApprovordaVO;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 审批细表 Service
 *
 * @Author AKITA
 * @Date 2025-04-23 14:10:18
 * @Copyright AKITA
 */

@Service
public class ApprovordaService {

    @Resource
    private ApprovordaDao approvordaDao;

    /**
     * 分页查询
     */
    public PageResult<ApprovordaVO> queryPage(ApprovordaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<ApprovordaVO> list = approvordaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(ApprovordaAddForm addForm) {
        ApprovordaEntity approvordaEntity = SmartBeanUtil.copy(addForm, ApprovordaEntity.class);
        approvordaDao.insert(approvordaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(ApprovordaUpdateForm updateForm) {
        ApprovordaEntity approvordaEntity = SmartBeanUtil.copy(updateForm, ApprovordaEntity.class);
        approvordaDao.updateById(approvordaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        approvordaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long docEntry) {
        if (null == docEntry){
            return ResponseDTO.ok();
        }

        approvordaDao.deleteById(docEntry);
        return ResponseDTO.ok();
    }
}
